package com.personnalManagerSystem.controller;


import com.personnalManagerSystem.model.Interview;
import com.personnalManagerSystem.model.Recruit;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;


import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liqing
 * @since 2022-04-06
 */
@Controller
@RequestMapping("/recruit")   //招聘需求
public class RecruitController  extends BaseController{
    @RequestMapping("/list")
    public String list(Model model,
                       String option,
                       String searchContent,
                       Integer pageNum,
                       Integer pageSize){
        baseList(model,option,searchContent,pageNum,pageSize,iRecruitService);
        return "view/recruit";
    }
    @RequestMapping("/add")
    public String add(@RequestParam(value = "number",required = false)Integer  number,
                      @RequestParam(value = "jobType",required = false) String jobType,
                      @RequestParam(value = "education",required = false)String education,
                      @RequestParam(value = "workYear",required = false) String workYear,
                      @RequestParam(value = "request",required = false)String request,
                      @RequestParam(value = "state",required = false)String state,
                      @RequestParam(value = "createTime",required = false)String createTime,
                      @RequestParam(value = "director",required = false)String director,
                      @RequestParam(value = "directorTel",required = true)String directorTel){
        Recruit recruit = new Recruit();
        LocalDate createTime1 = LocalDate.parse(createTime);
        //set注入
        recruit.setCreateTime(createTime1);
        recruit.setNumber(number);
        recruit.setJobType(jobType);
        recruit.setEducation(education);
        recruit.setWorkYear(workYear);
        recruit.setRequest(request);
        recruit.setState(state);
        recruit.setDirector(director);
        recruit.setDirectorTel(directorTel);
        iRecruitService.save(recruit);
        return "redirect:/recruit/list";
    }



    @RequestMapping("/edit")
    public String edit(@RequestParam(value = "id",required = false)Integer id,
                       @RequestParam(value = "number",required = false)Integer  number,
                       @RequestParam(value = "jobType",required = false) String jobType,
                       @RequestParam(value = "education",required = false)String education,
                       @RequestParam(value = "workYear",required = false) String workYear,
                       @RequestParam(value = "request",required = false)String request,
                       @RequestParam(value = "state",required = false)String state,
                       @RequestParam(value = "createTime",required = false)String createTime,
                       @RequestParam(value = "director",required = false)String director,
                       @RequestParam(value = "directorTel",required = true)String directorTel){
        Recruit recruit = new Recruit();
        LocalDate createTime1 = LocalDate.parse(createTime);
        //set注入
        recruit.setCreateTime(createTime1);
        recruit.setId(id);
        recruit.setNumber(number);
        recruit.setJobType(jobType);
        recruit.setEducation(education);
        recruit.setWorkYear(workYear);
        recruit.setRequest(request);
        recruit.setState(state);
        recruit.setDirector(director);
        recruit.setDirectorTel(directorTel);
        iRecruitService.saveOrUpdate(recruit);
        return "redirect:/recruit/list";
    }
    @RequestMapping("/del")
    public String del(@RequestParam(value = "id",required = true)Integer id){
        System.out.println("id:"+id);
        iRecruitService.removeById(id);
        return "redirect:/recruit/list";
    }



}

